package com.lmx.persistence.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lmx.common.constants.CommonConstants;
import com.lmx.persistence.service.common.BaseCrudServiceImpl;
import com.lmx.repoDomain.tmodel.CustomerPreference;
import com.lmx.repoDomain.tmodel.RelServicePreference;

@Service(value = "customerPreferenceService")
public class CustomerPreferenceServiceImpl extends
		BaseCrudServiceImpl<CustomerPreference> implements
		CustomerPreferenceService {
	@Autowired
	private RelServicePreferenceService relServicePreferenceService;

	@Override
	public CustomerPreference update(CustomerPreference customerPreference) {
		if (customerPreference.getDelStatus() == 1) {
			List<RelServicePreference> rels = this.relServicePreferenceService
					.find("preference.id", customerPreference.getId());
			rels.forEach(p -> {
				p.setDelStatus(CommonConstants.DEL_STATUS_YES_1);
				this.relServicePreferenceService.update(p);
			});
		}
		return super.update(customerPreference);
	}
}
